Skip to content

create an extension point to let users override wiki page lookups#148

Merged
lervag merged 1 commit intolervag:masterfrom
trashhalo:master
May 1, 2021
Merged

create an extension point to let users override wiki page lookups#148
lervag merged 1 commit intolervag:masterfrom
trashhalo:master

Conversation

@trashhalo
Copy link
Copy Markdown
Contributor

@trashhalo trashhalo commented Apr 29, 2021

Intent

I wish to use vim to edit my notes but my main notes editor is https://obsidian.md. They allow fuzzy links like [[Bunny]] goes to a Bunny.md file that can exist anywhere in your tree. This is different from wiki.vim link behavior.

How

Allow users to define a function named WikiSearchCommand that takes wiki_root and fname and outputs the transformed fname.

Example usage

In my vimrc to get wiki.vim to support obsidian links:

function! WikiSearchCommand(wiki_root, fname)
  let files = systemlist(printf('pushd %s && fd -e "md" "%s" |tail -n1 && popd', a:wiki_root, a:fname))
  return get(files, 0, a:fname)
endfunction

@lervag
Copy link
Copy Markdown
Owner

lervag commented Apr 30, 2021

Thanks for the suggestion and the PR! My initial thought is that you are on to something that looks smart, but that I will probably want to make some adjustments before merging this. I have a busy weekend, so I will not be able to give a detailed response and review until probably Monday or Tuesday, but stay tuned. I will get back to you as soon as I get the time!

@trashhalo
Copy link
Copy Markdown
Contributor Author

trashhalo commented Apr 30, 2021

Thanks for the suggestion and the PR! My initial thought is that you are on to something that looks smart, but that I will probably want to make some adjustments before merging this. I have a busy weekend, so I will not be able to give a detailed response and review until probably Monday or Tuesday, but stay tuned. I will get back to you as soon as I get the time!

Yay! I'm not a vimscript dev so I was just hacking my way to it working. 💯 Change everything!

lervag added a commit that referenced this pull request May 1, 2021
@lervag lervag merged commit 4698583 into lervag:master May 1, 2021
@lervag
Copy link
Copy Markdown
Owner

lervag commented May 1, 2021

I changed this quite abit, but I think it should still work as you want it to. Try the following settings:

function! WikiSearchCommand(fname, origin)
  if empty(a:fname) | return a:origin | endif

  call wiki#paths#pushd(wiki#get_root())
  let files = systemlist(printf('fd -e "md" "%s" |tail -n1', a:fname))
  call map(files, {_, x -> fnamemodify(x, ':p')})
  call wiki#paths#popd()

  return get(files, 0, a:fname)
endfunction

let g:wiki_resolver = 'WikiSearchCommand'

See :help wiki_resolver for the help text. Note that the return value must be an absolute path. And please, let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants